import { followUser  , cancelUser  , followQuestions , cancelQuestions } from '@/api/me.js'
export const mixin={
    methods: {
		//关注人和取消关注
		follow_person( info , id  ){
			//关注人
			if( info.is_follow == 0 ){
				followUser({
					user_id: id,
				})
				.then(res => {
					this.$refs.uToast.show({
						message: '关注成功',
						type: 'success'
					});
					//更新视图
					info.is_follow = 1;
				})
			}else{ //取消关注人
				cancelUser({ user_id: id }).then(res => {
					this.$refs.uToast.show({
						message: '取消关注',
						type: 'success'
					});
					//更新视图
					info.is_follow = 0;
				})
			}
		},
		follow_questions( info , id  ){
			if( info.is_follow == 0 ){
				followQuestions({
					id:id
				}).then(res=>{
					this.$refs.uToast.show({
						message: '关注成功',
						type: 'success'
					});
					//更新视图
					info.is_follow = 1;
				})
			}else{
				cancelQuestions({
					id:id
				}).then(res=>{
					this.$refs.uToast.show({
						message: '取消关注',
						type: 'success'
					});
					//更新视图
					info.is_follow = 0;
				})
			}
		},
		//关注方法
		followFn( id , info  , type ){
			//1. 判断是否是登录状态
			if( !this.$store.state.user.status ){
				this.$u.route('/pages/login/login');
				return false;
			}
			//2. 判断是关注人 还是 问题
			if( type == 'questions' ){
				this.follow_questions( info , id );
			}else{
				this.follow_person( info , id );
			}
		},
		//点赞 
        load( arr , index , type ){
			uni.showLoading({
				title:'点赞中...'
			})
			setTimeout(()=>{
				uni.hideLoading();
				uni.showToast({
					title:'点赞成功',
					duration:2000,
					icon:'none',
					complete(){
						if( arr ){
							arr[index][type]++;
						}
					}
				})
			},1000)
	    },
		
    }
}
